package com.gy.algorithm.carl.hashtableexa;

import java.util.HashMap;
import java.util.Map;

/**
 * @BelongsProject: javabase
 * @BelongsPackage: com.gy.algorithm.carl
 * @Author: gy
 * @Date: 2024/10/22 11:30
 * @Description:
 */
public class CanConstruct383 {

    public static void main(String[] args) {
        
    }

    // end1
//    public static boolean canConstruct(String ransomNote, String magazine) {
//
//    }

    // write
    public static boolean canConstruct(String ransomNote, String magazine) {
        int[] records = new int[26];

        for (int i = 0; i < magazine.length(); i++) {
            records[magazine.charAt(i) - 'a'] ++;
        }

        for (int i = 0; i < ransomNote.length(); i++) {
            records[ransomNote.charAt(i) - 'a'] --;
            if(records[ransomNote.charAt(i) - 'a'] < 0){
                return false;
            }
        }

        return true;
    }
}
